package nc.bs.lm4k;

import nc.vo.ic.pub.bill.SpecialBillItemVO;
import nc.vo.pub.BusinessException;
import nc.vo.pub.VOStatus;
import nc.vo.scm.pub.smart.ObjectUtils;

public class Lm4KWriteBack {
	public void reWriteNum(SpecialBillItemVO[] itemVOS, boolean flag)
			throws BusinessException {

		if (itemVOS == null || itemVOS.length == 0)
			return;

		try {
			SpecialBillItemVO[] itemvos = (SpecialBillItemVO[]) ObjectUtils
					.serializableClone(itemVOS);
			ReWriteBackTool.setVsourcebilltype("csourcetype");
			ReWriteBackTool.setVsourcebillid("csourcebillhid");
			ReWriteBackTool.setVsourcebillrowid("csourcebillbid");
			ReWriteBackTool.setPrimarykey("cspecialbid");
			ReWriteBackTool.setTablename("ic_special_b");

			if (flag) {
				ReWriteBackTool.writeBack(itemvos, "pn_turn_b",
						"pk_body", new String[] { "dshldtransnum" },
						new String[] { "reserve6" }, new String[] { "nturnnum" },
						true);
			} else {
				for (int i = 0; i < itemvos.length; i++) {
					itemvos[i].setStatus(VOStatus.DELETED);
				}
				ReWriteBackTool.writeBack(itemvos, "pn_turn_b",
						"pk_body", new String[] { "dshldtransnum" },
						new String[] { "reserve6" }, new String[] { "nturnnum" },
						true);
			}
		} catch (Exception e) {
			if (e instanceof BusinessException)
				throw (BusinessException) e;
			else
				throw new BusinessException(e.getMessage());
		}
	}
}
